package ch.uzh.ifi.seal.ssqa.metrics.heatmap;

import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import ch.uzh.ifi.seal.ssqa.metrics.CyclomaticComplexityMetric;
import ch.uzh.ifi.seal.ssqa.model.DiagramComponent;

public class CyclomaticComplexityHeatMap implements IHeatMap{

	private String name = "Cyclomatic Complexity";
	
	List<DiagramComponent> components; 
	
	Map<String, Double> resultMap = new HashMap<String, Double>();
	
	private Double minValue, maxValue;
	
	/**
	 * @param components
	 */
	public CyclomaticComplexityHeatMap(List<DiagramComponent> components){
			this.components = components;
	}
	
	public void calculateMap(){
		for(DiagramComponent component : components){
			CyclomaticComplexityMetric metric = new CyclomaticComplexityMetric();
			this.resultMap.put(component.getIdentifier(), metric.calculateResult(component).getResult());
		}
		Double[] values = this.resultMap.values().toArray(new Double[0]);
		Arrays.sort(values);
		this.minValue = values[0];
		this.maxValue = values[values.length-1];
	}
	
	@Override
	public Map<String, Double> getHeatMapping() {
		this.calculateMap();
		return this.resultMap;
	}
	
	public Double getMinValue(){
		return this.minValue;
	}
	
	public Double getMaxValue(){
		return this.maxValue;
	}
	
	@Override
	public String getName() {
		return name;
	}
}
